[PVFB][TOOLS] Change the configuration syntax for PVFB backends to more
authorSteven Smith <ssmith@xensource.com>
Fri, 1 Dec 2006 11:49:30 +0000 (11:49 +0000)
committerSteven Smith <ssmith@xensource.com>
Fri, 1 Dec 2006 11:49:30 +0000 (11:49 +0000)
closely match that of other devices.

This involves moving the logic for backend creation out of the image
handlers and in to the device handler, which is a much more sensible
place for it.

Signed-off-by: Steven Smith <sos22@cam.ac.uk>
tools/python/xen/xend/XendDomainInfo.py
tools/python/xen/xend/image.py
tools/python/xen/xend/server/vfbif.py
tools/python/xen/xm/create.py

index 152022477eb686b1947490b7bd12628f93a52d0e..d606dbb7bb34bba798da60201a76d38b88a28a40 100644 (file)
@@ -458,7 +458,7 @@ class XendDomainInfo:
             try:
                 self._constructDomain()
                 self._storeVmDetails()
-                self._restoreDomain()
+                self._createDevices()
                 self._createChannels()
                 self._storeDomDetails()
                 self._endRestore()
@@ -1387,23 +1387,6 @@ class XendDomainInfo:
             raise VmError(str(exn))
 
 
-    def _restoreDomain(self):
-        log.debug('XendDomainInfo.restoreDomain: %s %s',
-                  self.domid,
-                  self.info['cpu_weight'])
-
-        if not self.infoIsSet('image'):
-            raise VmError('Missing image in configuration')
-
-        try:
-            self.image = image.create(self,
-                                      self.info['image'],
-                                      self.info['device'])
-
-            self._createDevices()
-        except RuntimeError, exn:
-            raise VmError(str(exn))
-
     def cleanupDomain(self):
         """Cleanup domain resources; release devices.  Idempotent.  Nothrow
         guarantee."""
index 10acfd6674f025b1f87091694c8d02deb9db2257..1023197927dd2dbeafe928f9c58798f19fdd1548 100644 (file)
@@ -23,7 +23,6 @@ import math
 import signal
 
 import xen.lowlevel.xc
-import xen.util.auxbin
 from xen.xend.XendConstants import REVERSE_DOMAIN_SHUTDOWN_REASONS
 from xen.xend.XendError import VmError, XendError
 from xen.xend.XendLogging import log
@@ -200,72 +199,6 @@ class LinuxImageHandler(ImageHandler):
                               ramdisk        = self.ramdisk,
                               features       = self.vm.getFeatures())
 
-    def configure(self, imageConfig, deviceConfig):
-        ImageHandler.configure(self, imageConfig, deviceConfig)
-
-        self.pid = 0
-        log.info("configuring linux guest")
-
-        # set up the graphics bits.
-        # FIXME: this is much like what we do for HVM, should it be 
-        # for all image types now?
-        self.display = sxp.child_value(imageConfig, 'display')
-        self.xauthority = sxp.child_value(imageConfig, 'xauthority')
-        self.vncconsole = sxp.child_value(imageConfig, 'vncconsole')
-        vncpasswd = sxp.child_value(imageConfig, 'vncpasswd')
-        self.vncpasswd = vncpasswd
-
-        self.vnc = sxp.child_value(imageConfig, 'vnc')
-        self.sdl = sxp.child_value(imageConfig, 'sdl')
-        if self.vnc:
-            self.vncdisplay = int(sxp.child_value(imageConfig, 'vncdisplay',
-                                                  self.vm.getDomid()))
-            self.vncunused = sxp.child_value(imageConfig, 'vncunused')
-            self.vnclisten = sxp.child_value(imageConfig, 'vnclisten')
-            if not(self.vnclisten):
-                self.vnclisten = xen.xend.XendRoot.instance().get_vnclisten_address()
-
-    def createDeviceModel(self):
-        if self.pid:
-            return
-        # Execute device model (for us, it's just the fb frontend)
-        if not self.vnc and not self.sdl:
-            return
-
-        if self.vnc:
-            args = [xen.util.auxbin.pathTo("xen-vncfb")]
-            if self.vncunused:
-                args += ['--unused']
-            elif self.vncdisplay:
-                args += [ "--vncport", "%d" %(5900 + self.vncdisplay,) ]
-            if self.vnclisten:
-                args += [ "--listen", self.vnclisten ]
-
-            # password check
-            if self.vncpasswd is None:
-                # get password from xend-config(if password omitted, None)
-                self.vncpasswd = xen.xend.XendRoot.instance().get_vncpasswd_default()
-
-                if self.vncpasswd is None:
-                    raise VmError('vncpasswd is not setup in the guest config or xend-config.')
-            if self.vncpasswd != '':
-                self.vm.storeVm("vncpasswd", self.vncpasswd)
-                log.info("vncpassword set to '%s'", self.vncpasswd)
-
-        elif self.sdl:
-            args = [xen.util.auxbin.pathTo("xen-sdlfb")]
-        args = args + [ "--domid", "%d" % self.vm.getDomid(),
-                        "--title", self.vm.info['name'] ]
-
-        env = dict(os.environ)
-        if self.display:
-            env['DISPLAY'] = self.display
-        if self.xauthority:
-            env['XAUTHORITY'] = self.xauthority
-        log.info("spawning video: %s", args)
-        self.pid = os.spawnve(os.P_NOWAIT, args[0], args, env)
-        log.info("device model pid: %d", self.pid)
-
     def destroy(self):
         if not self.pid:
             return
index 7f9691698fae26c9d0201dccf059e6b74434d94c..45400316331653c583bb2256066fb87adc690f43 100644 (file)
@@ -1,5 +1,9 @@
 from xen.xend.server.DevController import DevController
 
+from xen.xend.XendError import VmError
+import xen.xend
+import os
+
 class VfbifController(DevController):
     """Virtual frame buffer controller. Handles all vfb devices for a domain.
     """
@@ -14,13 +18,37 @@ class VfbifController(DevController):
         front = {}
         return (devid, back, front)
 
+    def createDevice(self, config):
+        DevController.createDevice(self, config)
+        std_args = [ "--domid", "%d" % self.vm.getDomid(),
+                     "--title", self.vm.getName() ]
+        t = config.get("type", None)
+        if t == "vnc":
+            # Try to start the vnc backend
+            args = [xen.util.auxbin.pathTo("xen-vncfb")]
+            if config.has_key("vncunused"):
+                args += ["--unused"]
+            elif config.has_key("vncdisplay"):
+                args += ["--vncport", "%d" % (5900 + config["vncdisplay"])]
+            vnclisten = config.get("vnclisten",
+                                   xen.xend.XendRoot.instance().get_vnclisten_address())
+            args += [ "--listen", vnclisten ]
+            os.spawnve(os.P_NOWAIT, args[0], args + std_args, os.environ)
+        elif t == "sdl":
+            args = [xen.util.auxbin.pathTo("xen-sdlfb")]
+            env = dict(os.environ)
+            if config.has_key("display"):
+                env['DISPLAY'] = config["display"]
+            if config.has_key("xauthority"):
+                env['XAUTHORITY'] = config["xauthority"]
+            os.spawnve(os.P_NOWAIT, args[0], args + std_args, env)
+        else:
+            raise VmError('Unknown vfb type %s (%s)' % (t, repr(config)))
+
 class VkbdifController(DevController):
     """Virtual keyboard controller. Handles all vkbd devices for a domain.
     """
 
-    def __init__(self, vm):
-        DevController.__init__(self, vm)
-
     def getDeviceDetails(self, config):
         """@see DevController.getDeviceDetails"""
         devid = 0
index c4bca1130a2a1b5385515e3b711d13662e7359b5..8b5301b9e8ba5643736541f50b33cdd6504cb8d7 100644 (file)
@@ -284,13 +284,17 @@ gopts.var('usbport', val='PATH',
           use="""Add a physical USB port to a domain, as specified by the path
           to that port.  This option may be repeated to add more than one port.""")
 
-gopts.var('vfb', val="no|yes'",
-          fn=set_bool, default=0,
-          use="Make the domain a framebuffer backend.")
-
-gopts.var('vkbd', val="no|yes'",
-          fn=set_bool, default=0,
-          use="Make the domain a keyboard backend.")
+gopts.var('vfb', val="type={vnc,sdl},vncunused=1,vncdisplay=N,vnclisten=ADDR,display=DISPLAY,xauthority=XAUTHORITY",
+          fn=append_value, default=[],
+          use="""Make the domain a framebuffer backend.
+          The backend type should be either sdl or vnc.
+          For type=vnc, connect an external vncviewer.  The server will listen
+          on ADDR (default 127.0.0.1) on port N+5900.  N defaults to the
+          domain id.  If vncunused=1, the server will try to find an arbitrary
+          unused port above 5900.
+          For type=sdl, a viewer will be started automatically using the
+          given DISPLAY and XAUTHORITY, which default to the current user's
+          ones.""")
 
 gopts.var('vif', val="type=TYPE,mac=MAC,bridge=BRIDGE,ip=IPADDR,script=SCRIPT,backend=DOM,vifname=NAME",
           fn=append_value, default=[],
@@ -521,8 +525,6 @@ def configure_image(vals):
 
     if vals.builder == 'hvm':
         configure_hvm(config_image, vals) 
-
-    configure_graphics(config_image, vals)        
        
     return config_image
     
@@ -575,12 +577,22 @@ def configure_usb(config_devs, vals):
         config_devs.append(['device', config_usb])
 
 def configure_vfbs(config_devs, vals):
-    if vals.vfb:
-        config_devs.append(['device', ['vfb', []]])
-
-def configure_vkbds(config_devs, vals):
-    if vals.vkbd:
-        config_devs.append(['device', ['vkbd', []]])
+    for f in vals.vfb:
+        d = comma_sep_kv_to_dict(f)
+        config = ['vfb']
+        if not d.has_key("type"):
+            d['type'] = 'sdl'
+        for (k,v) in d.iteritems():
+            if not k in [ 'vnclisten', 'vncunused', 'vncdisplay', 'display',
+                          'xauthority', 'type' ]:
+                err("configuration option %s unknown to vfbs" % k)
+            config.append([k,v])
+        if not d.has_key("display") and os.environ.has_key("DISPLAY"):
+            config.append(["display", os.environ['DISPLAY']])
+        if not d.has_key("xauthority"):
+            config.append(["xauthority", get_xauthority()])
+        config_devs.append(['device', ['vkbd']])
+        config_devs.append(['device', config])
 
 def configure_security(config, vals):
     """Create the config for ACM security labels.
@@ -678,20 +690,13 @@ def configure_vifs(config_devs, vals):
         config_devs.append(['device', config_vif])
 
 
-def configure_graphics(config_image, vals):
-    """Create the config for graphic consoles.
-    """
-    args = [ 'vnc', 'vncdisplay', 'vncconsole', 'vncunused',
-             'sdl', 'display', 'xauthority', 'vnclisten', 'vncpasswd']
-    for a in args:
-        if (vals.__dict__[a]):
-            config_image.append([a, vals.__dict__[a]])
-
 def configure_hvm(config_image, vals):
     """Create the config for HVM devices.
     """
     args = [ 'device_model', 'pae', 'vcpus', 'boot', 'fda', 'fdb',
              'localtime', 'serial', 'stdvga', 'isa', 'nographic', 'soundhw',
+             'vnc', 'vncdisplay', 'vncunused', 'vncconsole', 'vnclisten',
+             'sdl', 'display', 'xauthority',
              'acpi', 'apic', 'usb', 'usbdevice', 'keymap' ]
     for a in args:
         if a in vals.__dict__ and vals.__dict__[a] is not None:
@@ -767,7 +772,6 @@ def make_config(vals):
     configure_usb(config_devs, vals)
     configure_vtpm(config_devs, vals)
     configure_vfbs(config_devs, vals)
-    configure_vkbds(config_devs, vals)
     configure_security(config, vals)
     config += config_devs